package pdd.d20210831.t2;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * <li style="color: red;">Prob</li>
 *
 * <li style="color: red;">Desc</li>
 *
 * <li style="color: red;">Link</li>
 *
 * @author habitplus
 * @since 2021-08-31 19:34
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        String[] arr = new String[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextLine();
        }
        MyCom com = new MyCom();
        Arrays.sort(arr, com);

        for (int i = 0; i < n; i++) {
            System.out.println(arr[i]);
        }
    }
}

class MyCom implements Comparator<String> {

    @Override
    public int compare(String o1, String o2) {
        if (o1 == null || o1.length() == 0 || o2 == null || o2.length() == 0) {
            return 0;
        }
        o1 = change(o1);
        o2 = change(o2);
        return o1.compareTo(o2);
    }

    private String change(String s) {
        char[] chs = s.toCharArray();
        int n = chs.length;
        char t;
        for (int i = 0; i < n / 2; i++) {
            if (chs[i] > chs[n - 1 - i]) {
                t = chs[i];
                chs[i] = chs[n - 1 - i];
                chs[n - 1 - i] = t;
            }
        }
        return new String(chs);
    }
}
